class Gun:
    def __init__(self, model):
        self.model = model
        self.bullet_count = 0


    def add_bullet(self, count):
        self.bullet_count = count

    def shoot(self):
        # 判断是否还有子弹
        if self.bullet_count <= 0:
            print('没有子弹了......')
            return
        else:
            # 发射一颗子弹
            print(f'{self.model} 开枪')
            self.bullet_count -= 1
            print("%s 发射子弹[%d]..."%(self.model, self.bullet_count))

class Soldier:
    def __init__(self, name, gun:Gun=None):
        self.name = name
        self.gun = gun



    def fire(self):
        # 判断士兵是否有枪
        if self.gun is None:
            print("[%s] 没有枪..." % self.name)
            return
        else:
            self.gun.add_bullet(30)
            self.gun.shoot()
            print("冲啊...[%s]" % self.name)

if __name__ == '__main__':
    # 创建枪对象
    # AK47 = Gun('AK47')
    # AK47.add_bullet(30)
    # AK47.shoot()
    # xusanduo = Soldier('许三多')
    # xusanduo.fire()
    # xusanduo.gun=AK47
    # xusanduo.fire()
    # wangwei = Soldier('王伟', Gun('AK47'))
    # wangwei.gun.add_bullet(30)
    # wangwei.fire()
    xuting = Soldier('许霆')
    xuting.fire()
    xuting.gun = Gun('AK47') # 给许霆添加一把枪
    xuting.fire()








